﻿<?php
require 'config_bd.php';
require 'cle_encrypt.php';
 
$uname     = $_REQUEST["name"];
$upass     = $_REQUEST["thePass"];
$udate     = $_REQUEST["theDate"];
$uhours    = $_REQUEST["hours"];
$udeleteid = $_REQUEST["deleteid"];
$uupsertid = $_REQUEST["upsertid"];
$uthisdate = $_REQUEST["thisdate"];

$sql =        "call fill_ftd_prc(get_user_id(:uname, AES_ENCRYPT(:upass ,:cle_encrypt)),    ";
$sql = $sql . "                              :pdate,     ";
$sql = $sql . "   get_hours_calc(get_user_id(:uname, AES_ENCRYPT(:upass ,:cle_encrypt)),:pupsertid,:phours,:pdate),";
$sql = $sql . "                              :pdeleteid, ";
$sql = $sql . "                              :pupsertid, ";
$sql = $sql . "                              :pthisdate )";


try {
    $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
	$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$stmt = $dbh->prepare($sql);  
	$stmt->bindParam("uname", $uname);
	$stmt->bindParam("upass", $upass);
	$stmt->bindParam("cle_encrypt", $cle_encrypt);
	$stmt->bindParam("pdate", $udate);
	$stmt->bindParam("phours", $uhours);
	$stmt->bindParam("pdeleteid", $udeleteid);
	$stmt->bindParam("pupsertid", $uupsertid);
	$stmt->bindParam("pthisdate", $uthisdate);
	$stmt->execute();
	$dbh = null;
	echo '{"items":"success"}'; 
} catch(PDOException $e) {
	echo '{"items":"error"}'; 
}

?>
